@extends("admin.base")
@section('app')
    <div v-loading="loading">
        @if($wd->state==0)
            <div style="margin-top: 15px">
                <el-input v-model="remark" placeholder="请输入审核备注"></el-input>
            </div>
            <div style="margin-top: 20px;
text-align: center;">
                <el-button type="success" @click="check(1)">通过并打款</el-button>
                <el-button type="danger" @click="check(2)">拒绝不通过</el-button>
                <el-button type="warning" @click="check(3)">拒绝并退款</el-button>
            </div>
        @endif
        @if($wd->state==2)
            <div style="margin-top: 15px">
                <el-input v-model="remark" placeholder="请输入退款备注"></el-input>
            </div>
            <div style="margin-top: 20px;
text-align: center;">
                <el-button type="warning" @click="check(3)">退款</el-button>
            </div>
        @endif
    </div>
@endsection
@section('js')
    <script>
        new Vue({
            el: '#app',
            data: function () {
                return {
                    loading: false,
                    remark: ''
                }
            },
            methods: {
                check(state) {
                    if (state > 1 && this.remark.length <= 0) {
                        this.$message.error('请输入审核备注');
                        return false;
                    } else if (state === 1 && this.remark.length <= 0) {
                        this.remark = "审核通过";
                    }
                    this.loading = true;
                    axios.post("{{route('admin-withdraw-check-data')}}", {
                        id: "{{$id}}",
                        state: state,
                        remark: this.remark
                    }).then(res => {
                        this.loading = false;
                        if (res.data.code === 200) {
                            this.$message.success(res.data.message);
                            setTimeout(function () {
                                window.parent.layer.closeAll()
                                window.parent.$.pjax.reload('#pjax-container');
                            }, 1500);

                        } else {
                            this.$message.error(res.data.message);
                        }

                    }, error => {
                        this.loading = false;
                        this.$message.error(error.response.data.message);
                    })
                }
            }
        });
    </script>
@endsection